package com.example.thymeleaf.controller;

import com.example.thymeleaf.entity.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.LinkedList;
import java.util.List;

/**
 * @Description :
 * @Author : Bruce Lee
 * @CreateTime : 2024/6/12
 */

@RestController
public class ThymeleafController {

    @GetMapping("/getStudents")
    public ModelAndView getStudent(){
        List<Student> students = new LinkedList<>();

        Student student = new Student();
        student.setId(1);
        student.setName("李四");
        student.setAge(21);
        Student student_two = new Student();
        student_two.setId(2);
        student_two.setName("张三");
        student_two.setAge(22);
        students.add(student);
        students.add(student_two);

        ModelAndView modelAndView = new ModelAndView();
        // 设置模板中的数据
        modelAndView.addObject("students",students);
        // 设置跳转模板名称
        modelAndView.setViewName("student");
        return modelAndView;
    }
}
